package cn.comtom.ewbs.signature.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.wf.captcha.GifCaptcha;
import com.wf.captcha.utils.CaptchaUtil;

import cn.comtom.ewbs.signature.common.vo.response.ApiResponse;
import io.swagger.annotations.Api;

@Api(value = "验证码")
@RestController
@RequestMapping("/open/captcha")
public class CaptchaController extends BaseController {

    /**
     * 验证码生成
     * @param request 请求报文
     * @param response 响应报文
     * */
    @RequestMapping("/captchaImage")
    public void generate(HttpServletRequest request, HttpServletResponse response) throws Exception {
        GifCaptcha gifCaptcha = new GifCaptcha(130,48,4);
        //静态验证码
        //SpecCaptcha gifCaptcha=new SpecCaptcha(130,48,4);
        CaptchaUtil.out(gifCaptcha, request, response);
    }

    /**
     * 异步验证
     * @param request 请求报文
     * @param captcha 验证码
     * @return 验证结果
     * */
    @RequestMapping("verify")
    public ApiResponse verify(HttpServletRequest request, String captcha){
        if(CaptchaUtil.ver(captcha,request)){
            return ApiResponse.ok();
        }
        return ApiResponse.error();
    }


}
